#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
    bool row[10][10];
    bool col[10][10];
    bool group[3][3][10];
public:
    void solveSudoku(vector<vector<char>>& board) {
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                if (board[i][j] != '.')
                {
                    int num = board[i][j] - '0';
                    row[i][num] = col[j][num] = group[i / 3][j / 3][num] = true;
                }
            }
        }
        dfs(board);
    }
    bool dfs(vector<vector<char>>& board)
    {
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                if (board[i][j] == '.')
                {
                    for (int g = 1; g <= 9; g++)
                    {
                        if (!row[i][g] && !col[j][g] && !group[i / 3][j / 3][g])
                        {
                            board[i][j] = g + '0';
                            row[i][g] = col[j][g] = group[i / 3][j / 3][g] = true;
                            if (dfs(board) == true)
                                return true;
                            board[i][j] = '.';
                            row[i][g] = col[j][g] = group[i / 3][j / 3][g] = false;
                        }
                    }
                    return false;
                }
            }
        }
        return true;
    }
};